package com.sci.web.util;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import com.sci.config.MyConstants;
import com.sci.web.business.admin.SysEnumsBusiness;
import com.sci.web.model.genmodel.SysEnums;
import com.sci.web.service.admin.SysEnumsService;

public class CommMethod {
	
	
	private static SysEnumsService sysEnumsService = new SysEnumsService();

	
	public static SysEnums getSysEnumsById(String id){
		return sysEnumsService.getSysEnumsById(id);
	}
	
	
	
	public  static List<SysEnums> getSysEnumsByMainKey(String mainKey){
		return sysEnumsService.getSysEnumsByMainKey(mainKey);

	}
	
	public static SysEnums getSysEnumsByKey(String mainKey , String eKey){
		return sysEnumsService.getSysEnumsByKey(mainKey, eKey);
	}
	
	public static String getSysEnumsByKeyToValue(String mainKey , String eKey){
		return sysEnumsService.getSysEnumsByKeyToValue(mainKey, eKey);
	}
	public static String getSysEnumsByKeyToValue(String key){
		return sysEnumsService.getSysEnumsByKeyToValue(key, key);
	}
	
	/**  
	* @Title: getSysEnumsByMainKey  
	* @Description: TODO(这里用一句话描述这个方法的作用)  
	* @param mainKey
	* @return      
	* @returnType List<SysEnums>      
	* @author LiuFei
	* @date 下午1:01:15
	* @throws  
	*/
	public static List<SysEnums> getSysEnumsByMainKeyStatic(String mainKey){
		List<SysEnums> enumList = MyConstants.enumList;
		List<SysEnums> list = new ArrayList<SysEnums>();
		if(enumList.size()>0){
			for (SysEnums sysEnums : enumList) {
				if(mainKey.equals(sysEnums.getMainKey())){
					list.add(sysEnums);
				}
			}
		}
		return list;
	}
	
	/**  
	* @Title: getSysEnumsByEKey  
	* @Description: TODO(这里用一句话描述这个方法的作用)  
	* @param eKey
	* @return      
	* @returnType SysEnums      
	* @author LiuFei
	* @date 下午1:01:24
	* @throws  
	*/
	public static SysEnums getSysEnumsByEKey(String eKey){
		List<SysEnums> enumList = MyConstants.enumList;
		for (SysEnums sysEnums : enumList) {
			if(eKey.equals(sysEnums.getEKey())){
				return sysEnums;
			}
		}
		return null;
	}
	
	public static String getSysEnumsByEKeyToValue(String eKey){
		List<SysEnums> enumList = MyConstants.enumList;
		for (SysEnums sysEnums : enumList) {
			if(eKey.equals(sysEnums.getEKey())){
				return sysEnums.getEValue();
			}
		}
		return null;
	}
	
	/**  
	* @Title: getSysEnumsByMainEKey  
	* @Description: TODO(这里用一句话描述这个方法的作用)  
	* @param mainKey
	* @param eKey
	* @return      
	* @returnType SysEnums      
	* @author LiuFei
	* @date 下午1:02:40
	* @throws  
	*/
	public SysEnums getSysEnumsByMainEKey(String mainKey ,  String eKey){
		List<SysEnums> enumList = MyConstants.enumList;
		if(enumList.size()>0){
			for (SysEnums sysEnums : enumList) {
				if(mainKey.equals(sysEnums.getMainKey())){
					if(eKey.equals(sysEnums.getEKey())){
						return sysEnums;
					}
				}
			}
		}
		return null;
	}

	
	
    public static final String createValiCode(int verificationCodeLength)  {
        //    所有候选组成验证码的字符，可以用中文
        String[] verificationCodeArrary={"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
               "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",
               "A","B","C","D","E","F","G","H","I","J", "K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"
               };
        String verificationCode = "";
        Random random = new Random();
        //此处是生成验证码的核心了，利用一定范围内的随机数做为验证码数组的下标，循环组成我们需要长度的验证码，做为页面输入验证、邮件、短信验证码验证都行
        for(int i=0;i<verificationCodeLength;i++){verificationCode += verificationCodeArrary[random.nextInt(verificationCodeArrary.length)];}
        return verificationCode;
    }
}
